local sk__qinyin = fk.CreateSkill {

  name = "sk__qinyin",

  tags = {  },

}



sk__qinyin:addEffect(fk.EventPhaseChanging, {
  name = "sk__qinyin",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__qinyin.name) and data.phase == Player.Discard
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #room:askForDiscard(player, 2, 2, true, sk__qinyin.name, true, ".", "#sk__qinyin-discard")
    room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
    if n == 0 then
      player:drawCards(2, sk__qinyin.name)
      for _, p in ipairs(room:getAlivePlayers()) do
        if not p.dead then
          room:loseHp(p, 1, sk__qinyin.name)
        end
      end
    else
      for _, p in ipairs(room:getAlivePlayers()) do
        if not p.dead and p:isWounded() then
          room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = sk__qinyin.name,
          })
        end
      end
    end
    if not player.dead and player:usedSkillTimes("sk__yeyan", Player.HistoryGame) > 0 and
      room:askForSkillInvoke(player, sk__qinyin.name, nil, "#sk__qinyin-invoke") then
      room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
      if n == 0 then
        for _, p in ipairs(room:getAlivePlayers()) do
          if not p.dead then
            room:loseHp(p, 1, sk__qinyin.name)
          end
        end
      else
        for _, p in ipairs(room:getAlivePlayers()) do
          if not p.dead and p:isWounded() then
            room:recover({
              who = p,
              num = 1,
              recoverBy = player,
              skillName = sk__qinyin.name,
            })
          end
        end
      end
    end
    data.skipped = true
  end,
})

return sk__qinyin